#!/bin/sh
###############################################################################
##  Author    : xuezhoyi
##  Name      : edw_mysql_dump.sh
##  Functions : for mysql dump
##  Purpose   : for mysql dump
##  Revisions or Comments
##  VER        DATE        AUTHOR           DESCRIPTION
##---------  ----------  ---------------  ------------------------------------ 
##  1.0      2017-05-22  xuezhouyi        1. CREATED THIS SHELL.
###############################################################################

V_PASSWD=${1}
V_DATE=$(date +%Y%m%d%H)
V_BD_LIST=(dmcode adm edw ods stg etl saiku log)

echo -e "\nStart to dump..."
for ((i=0; i<${#V_BD_LIST[@]}; i++));do
    mysqldump --databases ${V_BD_LIST[i]} -uroot -p${V_PASSWD} -RE --triggers > "${V_BD_LIST[i]}_${V_DATE}.dmp"
    echo "Info:DB ${V_BD_LIST[i]} has done."
done

echo -e "\nStart to gzip..."
for ((i=0; i<${#V_BD_LIST[@]}; i++));do
    gzip -v ${V_BD_LIST[i]}_${V_DATE}.dmp
done

echo -e "\nStart to tar..."
for ((i=0; i<${#V_BD_LIST[@]}; i++));do
    V_GZIP_LIST="${V_GZIP_LIST} ${V_BD_LIST[i]}_${V_DATE}.dmp.gz"
done
tar -czvf "MYSQL_${V_DATE}.tar.gz" "${V_GZIP_LIST}"
rm -f "${V_GZIP_LIST}"
